package com.beiju.system.controller;

/**
 * @version v1.0
 * @ClassName: SysStudentController.java
 * @Description: TODO(一句话描述该类的功能)
 * @Author: BeiJu
 * @Date: 2021/10/14 9:54
 */

import com.beiju.common.annotation.Log;
import com.beiju.common.core.controller.BaseController;
import com.beiju.common.core.domain.AjaxResult;
import com.beiju.common.core.page.TableDataInfo;
import com.beiju.common.enums.BusinessType;
import com.beiju.common.utils.poi.ExcelUtil;
import com.beiju.system.domain.SysStudent;
import com.beiju.system.service.ISysStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 学生信息Controller
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/student")
public class SysStudentController extends BaseController
{
	@Resource
	private ISysStudentService sysStudentService;

	/**
	 * 查询学生信息列表
	 */
	@PreAuthorize("@ss.hasPermi('system:student:list')")
	@GetMapping("/list")
	public TableDataInfo list(SysStudent sysStudent)
	{
		startPage();
		List<SysStudent> list = sysStudentService.queryList(sysStudent);
		return getDataTable(list);
	}

	/**
	 * 导出学生信息列表
	 * 先生存Excel数据，前端再根据返回的文件名去下载文件
	 */
	@PreAuthorize("@ss.hasPermi('system:student:export')")
	@Log(title = "学生信息", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult export(SysStudent sysStudent)
	{
		List<SysStudent> list = sysStudentService.queryList(sysStudent);
		ExcelUtil<SysStudent> util = new ExcelUtil<>(SysStudent.class);
		return util.exportExcel(list, "student");
	}

	/**
	 * 获取学生信息详细信息
	 */
	@PreAuthorize("@ss.hasPermi('system:student:query')")
	@GetMapping(value = "/{studentId}")
	public AjaxResult getInfo(@PathVariable("studentId") Long studentId)
	{
		return AjaxResult.success(sysStudentService.getById(studentId));
	}

	/**
	 * 新增学生信息
	 */
	@PreAuthorize("@ss.hasPermi('system:student:add')")
	@Log(title = "学生信息", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody SysStudent sysStudent)
	{
		return toAjax(sysStudentService.save(sysStudent));
	}

	/**
	 * 修改学生信息
	 */
	@PreAuthorize("@ss.hasPermi('system:student:edit')")
	@Log(title = "学生信息", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody SysStudent sysStudent)
	{
		return toAjax(sysStudentService.updateById(sysStudent));
	}

	/**
	 * 删除学生信息
	 */
	@PreAuthorize("@ss.hasPermi('system:student:remove')")
	@Log(title = "学生信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{studentIds}")
	public AjaxResult remove(@PathVariable Long[] studentIds)
	{
		return toAjax(sysStudentService.removeByIds(Arrays.asList(studentIds)));
	}
}